package com.example.finance_manager.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.finance_manager.db.SQLiteHelper;
import com.example.finance_manager.models.Flag;
import com.example.finance_manager.models.User;

import java.util.ArrayList;
import java.util.List;

public class FlagDao {
    private final SQLiteHelper sqLiteHelper;
    private SQLiteDatabase db;

    public FlagDao(Context context) {
        sqLiteHelper = new SQLiteHelper(context);
    }

    public long add(Flag flag) {
        db = sqLiteHelper.getWritableDatabase();
        ContentValues cv = getContentValues(flag);
        return db.insert("flag", null, cv);
    }

    public List<Flag> findAll() {
        List<Flag> list = new ArrayList<Flag>();
        db = sqLiteHelper.getReadableDatabase();
        Cursor cursor = db.query("flag", new String[]{"id", "contain"}, null, null, null, null, null);
        while (cursor.moveToNext()) {
            Flag flag = new Flag();
            System.out.println(cursor.getInt(0));
            flag.setId(cursor.getInt(0));
            flag.setContain(cursor.getString(1));
            list.add(flag);
        }
        return list;
    }

    private ContentValues getContentValues(Flag flag) {
        ContentValues cv = new ContentValues();
        cv.put("contain", flag.getContain());
        return cv;
    }
}
